//
//  RMMTuiKuaiJieGuoView.m
//  Romomo
//
//  Created by puman on 2017/2/14.
//  Copyright © 2017年 mazegong. All rights reserved.
//

#import "RMMTuiKuaiJieGuoView.h"

@implementation RMMTuiKuaiJieGuoView
{
    UIView *_backView;
    UILabel *_tuiKanDoneLabel;
    UIView *_lineView;
    UIImageView *_imageV;
    UILabel *_tjsqTimeLabel;
    UILabel *_yjdkTimeLabel;
    UILabel *_ysdtLabel;
    UILabel *_tjsqLabel;
    UILabel *_moneyLabel;
    UILabel *_typeLabel;
    UILabel *_spShuoMLabel;
    UILabel *_orderNoLabel;
    UILabel *_tuiKuanNoLabel;
}
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = kCColor;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 44)];
        label.textColor = COLORFROMCODE(0x9B9B9B, 1);
        label.font = kFont(13);
        label.text = @"退款进度";
        [self addSubview:label];
        
        for (int i = 0; i < 2; i++) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 44 + 75 * i, self.width, 74)];
            view.backgroundColor = kWhiteColor;
            [self addSubview:view];
            
            UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(14, 22, 30, 30)];
            imageV.layer.masksToBounds = YES;
            imageV.layer.cornerRadius = 15;
            [view addSubview:imageV];
            
            UILabel *tLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageV.right + 15, imageV.top, view.width - imageV.right - 30, 20)];
            tLabel.textColor = COLORFROMCODE(0x303137, 1);
            tLabel.font = kFont(14);
            [view addSubview:tLabel];
            
            UILabel *fLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageV.right + 15, tLabel.bottom, 130, 20)];
            fLabel.textColor = COLORFROMCODE(0x9B9B9B, 1);
            fLabel.font = kFont(12);
            [view addSubview:fLabel];

            
            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(imageV.left + (imageV.width - 2) / 2 , imageV.bottom, 2, 22)];
            lineView.backgroundColor = kBasicColor;
            [view addSubview:lineView];
            if ( i == 0) {
                tLabel.text = @"退款申请已提交,等待系统处理";
                imageV.image = [UIImage imageNamed:@"退款进度-1@3x"];
                _tjsqTimeLabel = fLabel;
            } else {
                tLabel.text = @"预计到账时间";
                _ysdtLabel = tLabel;
                _imageV = imageV;
                _yjdkTimeLabel = fLabel;
                lineView.frame = CGRectMake(imageV.left + (imageV.width - 2) / 2 , imageV.top - 22, 2, 22);
                lineView.backgroundColor = kCColor;
                imageV.image = [UIImage imageNamed:@"退款进度-2@3x"];
                _lineView = lineView;
                _tuiKanDoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(view.width - 115, 0, 100, view.height)];
                _tuiKanDoneLabel.textColor = COLORFROMCODE(0x9B9B9B, 1);
                _tuiKanDoneLabel.text = @"退款完成";
                _tuiKanDoneLabel.textAlignment = NSTextAlignmentRight;
                [view addSubview:_tuiKanDoneLabel];
                
            }
        }
        _backView = [[UIView alloc] initWithFrame:CGRectMake(15, 200, self.width - 30, 188)];
        _backView.layer.masksToBounds = YES;
        _backView.layer.cornerRadius = 3;
        _backView.backgroundColor = kWhiteColor;
        [self addSubview:_backView];
        
        NSArray *array = @[@"退款金额",@"退款方式",@"商品说明",@"订单号",@"退款编号"];
        for (int i = 0; i < 5; i++) {
            UILabel *labelA = [[UILabel alloc] initWithFrame:CGRectMake(15, 55 * i, 100, 54)];
            labelA.textColor = COLORFROMCODE(0x9B9B9B, 1);
            labelA.font = kFont(14);
            labelA.text = array[i];
            [_backView addSubview:labelA];
            
            if (i == 0) {
                labelA.font = kFont(16);
                UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, labelA.bottom, _backView.width, 1)];
                lineView.backgroundColor = kCColor;
                [_backView addSubview:lineView];
            } else if (i > 0 && i < 4) {
                labelA.frame = CGRectMake(15, 55 + 30 * (i - 1), 100, 30);
            } else {
                UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, 144, _backView.width - 30, 1)];
                lineView.backgroundColor = kCColor;
                [_backView addSubview:lineView];
                labelA.frame = CGRectMake(15, lineView.bottom, 100, 44);
            }
            UILabel *labelB = [[UILabel alloc] initWithFrame:CGRectMake(labelA.right, labelA.top, _backView.width - 30 - labelA.width, labelA.height)];
            labelB.textAlignment = NSTextAlignmentRight;
            labelB.numberOfLines = 0;
            labelB.textColor = COLORFROMCODE(0x2C2C2C , 1);
            labelB.font = kFont(14);
            [_backView addSubview:labelB];
            switch (i) {
                case 0:
                    labelB.font = kFont(16);
                    labelB.textColor = kBasicColor;
                    _moneyLabel = labelB;
                    break;
                case 1:
                    _typeLabel = labelB;
                    break;
                case 2:
                    _spShuoMLabel = labelB;
                    break;
                case 3:
                    _orderNoLabel = labelB;
                    break;
                case 4:
                    _tuiKuanNoLabel = labelB;
                    break;

                    
                default:
                    break;
            }
        }
    }
    return self;
}
- (void)setTime:(NSString *)time{
    NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    _tjsqTimeLabel.text = [[dateFormatter stringFromDate:date] substringToIndex:10];
    _tuiKanDoneLabel.hidden = YES;
    _backView.hidden = YES;
    _imageV.image = [UIImage imageNamed:@"退款进度-2@3x"];
    _ysdtLabel.text = @"预计到账时间";
    _lineView.backgroundColor = kCColor;
    _yjdkTimeLabel.text = [[dateFormatter stringFromDate:[[NSDate alloc] initWithTimeInterval:5 * 24 * 3600 sinceDate:date]] substringToIndex:10];

}
- (void)setDic:(NSDictionary *)dic{
    if ([dic[@"ORDER_STATUS"] isEqualToString:@"8"]) {
        // 退单中
        _tuiKanDoneLabel.hidden = YES;
        _backView.hidden = YES;
        _imageV.image = [UIImage imageNamed:@"退款进度-2@3x"];
        _ysdtLabel.text = @"预计到账时间";
        _lineView.backgroundColor = kCColor;
        _tjsqTimeLabel.text = [dic[@"RETURN_TIME"] substringToIndex:10];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *date = [dateFormatter dateFromString:dic[@"RETURN_TIME"]];
        NSDate *time = [[NSDate alloc] initWithTimeInterval:5 * 24 * 60 * 60 sinceDate:date];
        _yjdkTimeLabel.text = [[dateFormatter stringFromDate:time] substringToIndex:10];
    } else {
        // 退款完成
        _tuiKanDoneLabel.hidden = NO;
        _backView.hidden = NO;
        _ysdtLabel.text = @"到账时间";
        _imageV.image = [UIImage imageNamed:@"退款进度-1@3x"];
        _lineView.backgroundColor = kBasicColor;
        _tjsqTimeLabel.text = [dic[@"RETURN_TIME"] substringToIndex:10];
        _yjdkTimeLabel.text = dic[@"LAST_MODI_DATE"];
        _moneyLabel.text = [NSString stringWithFormat:@"%@",dic[@"RETURN_AMT"]];
        _typeLabel.text = [NSString stringWithFormat:@"%@",dic[@"PAY_NAME"]];
        _spShuoMLabel.text = dic[@"PROD_NAME"];
        _orderNoLabel.text = dic[@"ORDER_NO"];
        _tuiKuanNoLabel.text = [RMMFileManager retrunObjWith:dic[@"RETURN_NO"]];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
